home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvm3 / src / pvmdpack.c < prev    next >
C/C++ Source or Header  |  1997-07-22  |  5KB  |  270 lines

  1.  
  2. static char rcsid[] =
  3.     "$Id: pvmdpack.c,v 1.6 1997/06/27 17:32:51 pvmsrc Exp $";
  4.  
  5. /*
  6.  *         PVM version 3.4:  Parallel Virtual Machine System
  7.  *               University of Tennessee, Knoxville TN.
  8.  *           Oak Ridge National Laboratory, Oak Ridge TN.
  9.  *                   Emory University, Atlanta GA.
  10.  *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
  11.  *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
  12.  *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
  13.  *                   (C) 1997 All Rights Reserved
  14.  *
  15.  *                              NOTICE
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software and
  18.  * its documentation for any purpose and without fee is hereby granted
  19.  * provided that the above copyright notice appear in all copies and
  20.  * that both the copyright notice and this permission notice appear in
  21.  * supporting documentation.
  22.  *
  23.  * Neither the Institutions (Emory University, Oak Ridge National
  24.  * Laboratory, and University of Tennessee) nor the Authors make any
  25.  * representations about the suitability of this software for any
  26.  * purpose.  This software is provided ``as is'' without express or
  27.  * implied warranty.
  28.  *
  29.  * PVM version 3 was funded in part by the U.S. Department of Energy,
  30.  * the National Science Foundation and the State of Tennessee.
  31.  */
  32.  
  33. /*
  34.  *    pvmdpack.c
  35.  *
  36.  *    Pvmd message packing and unpacking.
  37.  *
  38. $Log: pvmdpack.c,v $
  39.  * Revision 1.6  1997/06/27  17:32:51  pvmsrc
  40.  * Updated for WIN32 header files & Authors.
  41.  *
  42.  * Revision 1.5  1997/06/24  20:39:18  pvmsrc
  43.  * Eliminated unnecessary global externs.
  44.  *
  45.  * Revision 1.4  1997/04/30  21:26:26  pvmsrc
  46.  * SGI Compiler Warning Cleanup.
  47.  *
  48.  * Revision 1.3  1997/01/28  19:27:22  pvmsrc
  49.  * New Copyright Notice & Authors.
  50.  *
  51.  * Revision 1.2  1996/10/24  21:04:49  pvmsrc
  52.  * Moved #include of "global.h" down below other headers:
  53.  *     - need to have all of the structures / types declared before
  54.  *         the globals can be declared...
  55.  *
  56.  * Revision 1.1  1996/09/23  23:44:32  pvmsrc
  57.  * Initial revision
  58.  *
  59.  *
  60.  */
  61.  
  62. #ifdef NEEDMENDIAN
  63. #include <machine/endian.h>
  64. #endif
  65. #ifdef NEEDENDIAN
  66. #include <endian.h>
  67. #endif
  68. #ifdef NEEDSENDIAN
  69. #include <sys/endian.h>
  70. #endif
  71. #ifndef WIN32
  72. #include <rpc/types.h>
  73. #include <rpc/xdr.h>
  74. #else
  75. #include "..\xdr\types.h"
  76. #include "..\xdr\xdr.h"
  77. #endif
  78. #include <pvm3.h>
  79. #include "pvmalloc.h"
  80. #include "pvmfrag.h"
  81. #include "pmsg.h"
  82. #include "listmac.h"
  83. #include "global.h"
  84.  
  85.  
  86. /***************
  87.  **  Private  **
  88.  **           **
  89.  ***************/
  90.  
  91.  
  92. /*****************
  93.  **  Interface  **
  94.  **             **
  95.  *****************/
  96.  
  97.  
  98. /*    pkbyte()
  99. *
  100. *    Pack bytes into a message.
  101. *    Returns 0 if ok.
  102. */
  103.  
  104. int
  105. pkbyte(mp, p, n)
  106.     struct pmsg *mp;        /* message to pack */
  107.     char *p;
  108.     int n;
  109. {
  110.     return (mp->m_codef->enc_byte) (mp, (void*)p, n, 1, 1);
  111. }
  112.  
  113.  
  114. /*    upkbyte()
  115. *
  116. *    Unpack bytes from a message.
  117. *    Returns 0 if ok.
  118. */
  119.  
  120. int
  121. upkbyte(mp, p, n)
  122.     struct pmsg *mp;        /* message to unpack */
  123.     char *p;                /* unpack into */
  124.     int n;
  125. {
  126. /*
  127.     pvmlogprintf("upkbyte(0x%lx, 0x%lx, %d)\n", (long)mp, (long)p, n);
  128. */
  129.     return (mp->m_codef->dec_byte) (mp, (void*)p, n, 1, 1);
  130. }
  131.  
  132.  
  133. /*    pkint()
  134. *
  135. *    Pack a integer into a message.
  136. *    Returns 0 if ok.
  137. */
  138.  
  139. int
  140. pkint(mp, i)
  141.     struct pmsg *mp;        /* message to pack */
  142.     int i;                    /* int to pack */
  143. {
  144.     return (mp->m_codef->enc_int) (mp, (void*)&i, 1, 1, sizeof(int));
  145. }
  146.  
  147.  
  148. /*    upkint()
  149. *
  150. *    Unpack a signed integer from a message.
  151. *    Returns 0 if ok.
  152. */
  153.  
  154. int
  155. upkint(mp, np)
  156.     struct pmsg *mp;        /* message to unpack */
  157.     int *np;                /* int to unpack into */
  158. {
  159.     return (mp->m_codef->dec_int) (mp, (void*)np, 1, 1, sizeof(int));
  160. }
  161.  
  162.  
  163. /*    upkuint()
  164. *
  165. *    Unpack an unsigned integer from a message.
  166. *    Returns 0 if ok.
  167. */
  168.  
  169. int
  170. upkuint(mp, np)
  171.     struct pmsg *mp;        /* message to unpack */
  172.     int *np;                /* int to unpack into */
  173. {
  174.     return (mp->m_codef->dec_uint) (mp, (void*)np, 1, 1, sizeof(int));
  175. }
  176.  
  177.  
  178. /*    pkstr()
  179. *
  180. *    Pack a null-term string into a message.
  181. *    Returns 0 if ok.
  182. */
  183.  
  184. int
  185. pkstr(mp, s)
  186.     struct pmsg *mp;        /* message to pack */
  187.     char *s;                /* string to pack */
  188. {
  189.     int cc;
  190.     int l = strlen(s) + 1;
  191.  
  192.     if (!(cc = (mp->m_codef->enc_int) (mp, (void*)&l, 1, 1, sizeof(int))))
  193.         cc = (mp->m_codef->enc_byte) (mp, (void*)s, l, 1, 1);
  194.     return cc;
  195. }
  196.  
  197.  
  198. /*    upkstr()
  199. *
  200. *    Unpack a string from a message.  Result is null-terminated.
  201. *    Any length greater than mlen is discarded from message..
  202. *    Returns 0 if ok.
  203. */
  204.  
  205. int
  206. upkstr(mp, s, mlen)
  207.     struct pmsg *mp;        /* message to unpack */
  208.     char *s;                /* space to unpack in */
  209.     int mlen;                /* max bytes to unpack incl null */
  210. {
  211.     int cc;
  212.     int l;
  213.  
  214.     if (!(cc = (mp->m_codef->dec_int) (mp, (void*)&l, 1, 1, sizeof(int)))) {
  215.         if (l <= 0)
  216.             cc = PvmNoData;
  217.         else if (l <= mlen)
  218.             cc = (mp->m_codef->dec_byte) (mp, (void*)s, l, 1, 1);
  219.         else
  220.             cc = PvmNoMem;
  221.     }
  222.     return cc;
  223. }
  224.  
  225.  
  226. /*    upkstralloc()
  227. *
  228. *    Unpack a string from a message.  Result is null-terminated,
  229. *    and in dynamic space..
  230. *    Returns 0 if ok.
  231. */
  232.  
  233. int
  234. upkstralloc(mp, ss)
  235.     struct pmsg *mp;        /* message to unpack */
  236.     char **ss;                /* return pointer */
  237. {
  238.     int cc;
  239.     int l;
  240.  
  241.     if (!(cc = (mp->m_codef->dec_int) (mp, (void*)&l, 1, 1, sizeof(int)))) {
  242.         if (l <= 0)
  243.             cc = PvmNoData;
  244.         else {
  245.             *ss = TALLOC(l, char, "ustr");
  246.             if ((cc = (mp->m_codef->dec_byte) (mp, (void*)*ss, l, 1, 1)) < 0) {
  247.                 PVM_FREE(*ss);
  248.                 *ss = 0;
  249.             }
  250.         }
  251.     }
  252.     return cc;
  253. }
  254.  
  255.  
  256. /*    mesg_rewind()
  257. *
  258. *    A hack to rewind a message.
  259. */
  260.  
  261. void
  262. mesg_rewind(mp)
  263.     struct pmsg *mp;
  264. {
  265.     mp->m_flag &= ~MM_UPACK;
  266.     (mp->m_codef->dec_init)(mp);
  267. }
  268.  
  269.  
  270.